package com.hongfasoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import uniesb.sdk.util.JSON;

import com.hongfasoft.util.DBManager;

public class ArticleList extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		response.setHeader("content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");

		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

//		String wxid = request.getParameter("wx");
		String menu = request.getParameter("menu");
		HashMap result = new HashMap();
		try
		{
			List<HashMap> articles = DBManager.getAllArticlList( false, menu);
			result.put("op.code", "Y");
			result.put("op.info", "获取成功");
			result.put("articles", articles);
			result.put("totalcount", articles != null ? articles.size() : 0);
		} catch (Exception e)
		{
			e.printStackTrace();
			result.put("op.code", "E");
			result.put("op.info", "服务器繁忙，稍候刷新");
		}

		out.write(JSON.toJSON(result));
		out.flush();
	}
}
